home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: truncation function?
- Date: 15 Feb 1996 00:47:57 -0500
- Organization: Montclair State University
- Message-ID: <harmon.824362384@pegasus.montclair.edu>
- References: <4fjc0k$nev$1@mhadg.production.compuserve.com>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- Steve Eckmann <71055.1153@CompuServe.COM> writes:
-
- >I need a truncation function "float trunc(float in; int
- >precision)" that
- >takes a float and a precision spec and returns the input float
- >truncated to
- >"precision" decimal digits. Similarly for "round". This seems so
- >simple
-
- #include <math.h>
-
- float trunc(float in, float epsilon)
- {
- if (in > (0.0 + epsilon)) return( (float) floor(in) );
- if (in < (0.0 - epsilon)) return( (float) ceil(in) );
- return( 0.0 );
- }
-
- -- Stone
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... 640K ought to be enough for anyone - Bill Gates '81
-
-